import 'dart:convert';

import 'package:flutter/cupertino.dart';
import 'package:geomancy/models/base_model.dart';
import 'package:geomancy/models/common_model.dart';
import 'package:geomancy/models/notification_list_model.dart';
import 'package:geomancy/tools/http.dart';

class SettingAPI {
  ///获取系统消息列表
  static Future<NotificationResultModel?> getSettingMsgList(BuildContext context, CommonPage page) async {
    try {
      final data = await Fetch.request(Method.POST, '/notifications/list', params: page.toJson(), context: context);
      final result = NotificationListModel.fromJson(json.decode(data.data));
      if (result.code == 200) {
        return result.data;
      }
      return null;
    } catch(e) {
      return null;
    }
  }
  ///获取系统消息详情
  static Future<NotificationItemModel?> getSettingMsgDetail(BuildContext context, int id) async {
    try {
      final data = await Fetch.request(Method.GET, '/notifications/detail/$id', context: context);
      final result = CommonModel.fromJson(json.decode(data.data));
      if (result.code == 200) {
        final NotificationItemModel msg = NotificationItemModel.fromJson(result.data);
        return msg;
      }
      return null;
    } catch(e) {
      return null;
    }
  }
}